function deepClone(obj, map = new WeakMap()) {
  if (typeof obj !== "object" || obj === null) return obj;
  if(obj instanceof RegExp) return RegExp(obj)
  if(obj instanceof Date) return Date(obj)
  if(map.has(obj)) return map.get(obj)
    let result=Array.isArray(obj)? []:{}
    map.set(obj,result)
    for(let ch of obj){
      if(obj.hasOwnProperty(ch)){
        result[ch]=deepClone(obj[ch],map)
      }
    }
    return result
}

const obj = {
  a: 1,
  b: { c: 2 },
};